package cn.edu.live.config;

import java.util.Properties;

import cn.edu.live.controller.ActivityController;
import cn.edu.live.controller.HelloController;
import cn.edu.live.controller.HomeController;
import cn.edu.live.controller.UserController;
import cn.edu.live.model.Anchor;
import cn.edu.live.model.History;
import cn.edu.live.model.LiveRoom;
import cn.edu.live.model.Question;
import cn.edu.live.model.Student;
import cn.edu.live.model.UserInfo;
import cn.edu.live.util.PropertyKit;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.ext.handler.ContextPathHandler;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.jfinal.render.ViewType;

/**
 * core config file
 * 
 * @author zhagz
 * 
 */
public class CoreConfig extends JFinalConfig {
	public void configConstant(Constants me) {
		me.setDevMode(true);
		me.setEncoding("utf-8");
		me.setViewType(ViewType.JSP);
	}

	public void configRoute(Routes me) {
		me.add("/", HomeController.class);
		me.add("/hello", HelloController.class);
		me.add("/user", UserController.class);
		me.add("/activity", ActivityController.class);
	}

	public void configPlugin(Plugins me) {
		Properties p = PropertyKit.load("db.properties");
		C3p0Plugin cp = new C3p0Plugin(p.getProperty("driver"), p.getProperty("user"), p.getProperty("password"));
		me.add(cp);

		ActiveRecordPlugin arp = new ActiveRecordPlugin(cp);
		me.add(arp);

		arp.addMapping("anchor", "id", Anchor.class);
		arp.addMapping("history", "id", History.class);
		arp.addMapping("liveRoom", "id", LiveRoom.class);
		arp.addMapping("userInfo", "id", UserInfo.class);
		arp.addMapping("question", "id", Question.class);
		arp.addMapping("student", "id", Student.class);
	}

	public void configInterceptor(Interceptors me) {
	}

	public void configHandler(Handlers me) {
		me.add(new ContextPathHandler("basePath"));
	}
}